import React from 'react';
import {Button, Form} from 'antd';
import {ModalFooter} from 'antd-extra';
import notify from '../../NotificationExtra';
import SiderTree from '../SiderTree';
import ComponentBase from '../../Base/ComponentBase';

/**
 * 入参：table， dispatch
 */
@Form.create()
//@connect(({ workOrder, global }) => ({ ...workOrder, ...global }))
class ModalSelectNode extends ComponentBase {
  constructor(props) {
    super(props);
    this.state = {
      checkedKeys: [],
    };
  }

  componentDidMount() {

  }

  close = () => {
    const { result } = this.props;
    const checkedKeys = this.state.checkedKeys;
    if (!checkedKeys || !checkedKeys.length) {
      notify({ message: '未选择目录', type: 'error' });
      return;
    }
    const { selectedNode } = this.state;

    result && result(selectedNode);
    this.props.modalRef.close();

  };

  onCheck = (key, selectedNode) => {
    this.setState({ checkedKeys: [key], selectedNode });
  };

  render() {
    const { form: {} } = this.props;
    const _props = { ...this.props };
    _props['onCheck'] =  this.onCheck;
    _props['disableEdit'] =  true;
    _props['checkable'] =  true;
    return (
      <Form>
        {
          <SiderTree
          {..._props}
        ></SiderTree>
        }

        <ModalFooter>
          <Button
            type="primary"
            onClick={() => {
              this.close();
            }}
          >确认
          </Button>
          <Button onClick={() => {
            this.props.modalRef.close();
          }}
          >取消
          </Button>
        </ModalFooter>
      </Form>
    );
  }
}

export default ModalSelectNode;
